<!DOCTYPE html>
<html>
<head>
    <title>订单编辑</title>
    <meta http-equiv="Content-Type">
    <meta content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=1">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<?php echo URLPRE; ?>static/hm/css/order_detail.css" type="text/css">
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.11.3/jquery.js
"></script>
    <script type="text/javascript" src="<?php echo URLPRE; ?>static/template/default/mobile/js/layer/layer.js"></script>


</head>

<body>
<div class="page active">
    <header class="list-head J_header fixed detail-header">
        <a class="back J_back" href="javascript:history.back();"></a>
        <div class="placeholder"></div>
        <div class="title"><i class="arr-dowm"></i>
            <p class="shop-title">订单详情</p>
            <div class="shop-item">
                <p class="shop-sub-title"><?php echo fdate($start); ?></p>
                <p class="shop-sub-title"><?php echo fdate($end); ?></p>
                <p class="shop-sub-title"><?php echo $hotel_order_info['number']; ?>
                    人</p>
                <p class="shop-sub-title"><?php echo $days ?>天</p>
                <p class="shop-sub-title"><?php echo $order_info['order_status_name'] . ' ' . $order_info['pay_status_name']; ?></p>
            </div>
            <div class="shop-item">
            <p class="shop-sub-title"><?php echo $rstr;?></p>
            </div>
        </div>
    </header>
    <div class="change">
        <div class="menu J_change change-btn chosed">菜单</div>
        <div class="details J_change change-btn">详情</div>
    </div>
    <div class="cate-list J_cate_list">
        <div class="list">
            <ul>

                <li class="J_cate J_goods_cate on">
                    <div class="cate-name ellipsis">菜品管理</div>
                    <span>0</span></li>
                <li class="J_cate J_drinks_cate">
                    <div class="cate-name ellipsis">酒水管理</div>
                    <span>0</span></li>
                <!-- <li class="J_cate cate-selection">
                     <div class="cate-name ellipsis">房间管理</div>
                     <span class="hide">0</span></li>-->
            </ul>
        </div>

    </div>
    <div class="dtl-scroll J_menu">
        <div class="spec-container J_spec_container">


            <div class="spec J_spec  J_goods" data-id="菜品管理">
                <p class="spec-tit">菜品管理</p>
                <ul class="dish-list">
                    <?php if ($goods_list): ?>
                        <?php foreach ($goods_list as $key => $item): ?>

                            <li class="J_dish selected ">
                                <div class="dish-basic">
                                    <div class="pic J_dishPic">
                                        <img src="http://p0.meituan.net/xianfu/c2a29f858bf91802584c231efc23037e75776.jpg@100w_100h_1e_1c">
                                    </div>
                                    <div class="content">
                                        <p class="dish"><?php echo $item['name']; ?></p>
                                        <p class="sale" style="visibility: hidden">
                                            <span>月售3480</span></p>
                                        <p class="price-con">
                                            <span class="price"><?php echo price_format($item['money']); ?></span>
                                        </p>
                                    </div>
                                    <div class="oper">
                                        <i class="add J_plus"><i>

                                            </i></i>
                                        <span class="num J_num">
                                            <span><?php echo $order_drinks[$item['id']]['number'] ? $order_drinks[$item['id']]['number'] : 0; ?></span>
                                        </span>
                                        <i class="minus J_minus"><i>

                                            </i></i>
                                        <input type="hidden" name="gids[]" class="J_input_id" value="<?php echo $item['id']; ?>">
                                        <input type="hidden" class="J_input_num" data-price="<?php echo $item['money']; ?>" name="gnums[]" value="<?php echo $order_drinks[$item['id']]['number'] ? $order_drinks[$item['id']]['number'] : 0; ?>">
                                    </div>
                                </div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
            </div>

            <div class="spec J_spec hide J_drinks" data-id="酒水管理">
                <p class="spec-tit">酒水管理</p>
                <p class="spec-tit J_scroll_tit hide">酒水管理</p>
                <ul class="dish-list">
                    <?php if ($drinks_list): ?>
                        <?php foreach ($drinks_list as $key => $item): ?>

                            <li class="J_dish selected ">
                                <div class="dish-basic">
                                    <div class="pic J_dishPic">
                                        <img src="http://p0.meituan.net/xianfu/c2a29f858bf91802584c231efc23037e75776.jpg@100w_100h_1e_1c">
                                    </div>
                                    <div class="content">
                                        <p class="dish"><?php echo $item['name']; ?></p>
                                        <p class="sale" style="visibility: hidden">
                                            <span>月售3480</span></p>

                                        <p class="price-con">
                                            <span class="price"><?php echo price_format($item['money']); ?></span>
                                        </p>
                                    </div>
                                    <div class="oper">
                                        <i class="add J_plus"><i></i></i><span class="num J_num"><span><?php echo $order_drinks[$item['id']]['number'] ? $order_drinks[$item['id']]['number'] : 0; ?></span></span><i class="minus J_minus"><i></i></i>
                                        <input type="hidden" name="gids[]" class="J_input_id" value="<?php echo $item['id']; ?>">
                                        <input type="hidden" data-price="<?php echo $item['money']; ?>" name="gnums[]" class="J_input_num" value="<?php echo $order_drinks[$item['id']]['number'] ? $order_drinks[$item['id']]['number'] : 0; ?>">
                                    </div>
                                </div>
                            </li>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
            </div>

        </div>

    </div>

    <div class="shopInfo J_shopInfo hide">

        <div class="shopDetail J_shopDetail">
            <div class="tip shopdet"><p>入住日期 : <?php echo $start; ?></p></div>
            <div class="tip shopdet"><p>离店日期 : <?php echo $end; ?></p></div>
            <div class="tip shopdet"><p>成人男
                    : <?php echo $hotel_order_info['male_number']; ?></p></div>
            <div class="tip shopdet"><p>成人女
                    : <?php echo $hotel_order_info['woman_number']; ?></p></div>
            <div class="tip shopdet"><p>儿童
                    : <?php echo $hotel_order_info['child_number']; ?></p></div>
            <div class="tip shopdet"><p>微信用户
                    : <?php echo $contact_info['wx_nick']; ?></p></div>
            <div class="tip shopdet"><p>姓名
                    : <?php echo $contact_info['name']; ?></p></div>
            <div class="tip shopdet"><p>手机号
                    : <?php echo $contact_info['phone_num']; ?></p></div>
        </div>

    </div>


    <input type="hidden" name="order_account" class="J_input_account" value="<?php echo intval($order_info['order_account']); ?>">

    <style>
        .btn-box .btn {
            width: 33.333%;
            font-size: 12px;
        }

        .btn-box .status-btn {
            width: 33.33%;
            color: #fff;
            height: 54px;
            float: left;
            text-align: center;
            font-size: 12px;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            padding: 0;
        }

        .btn-box .status-btn div {
            margin: 10px;

            padding: 0;
            line-height: 34px;
            -webkit-border-radius: 3px;
            border-radius: 3px;
        }

        .btn_success {
            background-color: #89bf00;
            background-position: 0 -240px;
            border-color: #6bad01 #6bad01 #63a100;
        }

        .btn_other {
            background-position: 0 -120px;
            background-color: #2b94d9;
            border-color: #2b94d9;
        }

        .btn_error {
            background-color: #f29307;
            background-position: 0 -360px;
            border-color: #e77c0e #e77c0e #dd7204;
        }

        .btn_red {
            background-position: 0 -120px;
            background-color: #d9534f;
            border-color: #d9534f;
        }


    </style>

    <script type="text/javascript">


        $(function () {


            var roomAccount = '<?php echo intval($order_info['room_account']);?>';
            var orderId = '<?php echo $order_info['order_id'];?>';
            var roomSelect = '<?php echo !empty($order_room) ? 1 : 0?>';
            $(function () {


                $.extend({
                    fn_calculate_account: function (type) {

                        var type = type ? type : 0;

                        var goods_account = 0;
                        var goods_number = 0;
                        $('.J_goods').find('.J_input_num').each(function () {
                            goods_account += Number($(this).val()) * Number($(this).data('price'));
                            goods_number += Number($(this).val());
                        })

                        var drink_account = 0;
                        var drink_number = 0;
                        $('.J_drinks').find('.J_input_num').each(function () {
                            drink_account += Number($(this).val()) * Number($(this).data('price'));
                            drink_number += Number($(this).val());
                        })


                        $('.J_goods_cate').find('span').text(goods_number);
                        $('.J_drinks_cate').find('span').text(drink_number);

                        if (!type) {
                            $('.J_order_account').text(Number(goods_account) + Number(drink_account) + Number(roomAccount) + '.00');
                            $('.J_input_account').val(Number(goods_account) + Number(drink_account) + Number(roomAccount));

                        }
                    }
                })

                $.fn_calculate_account(1);

                $('.J_cate_list .J_cate').on('touchstart', function () {
                    $(this).addClass('on').siblings('li').removeClass('on');
                    var cat_name = $(this).children('.cate-name').text();

                    $('.J_spec_container').find('.J_spec[data-id="' + cat_name + '"]').removeClass('hide').siblings('.J_spec').addClass('hide');
                })


                $('.J_change').on('touchstart', function () {
                    $(this).addClass('chosed').siblings('.J_change').removeClass('chosed');
                    var text = $(this).text();

                    if (text == '菜单') {
                        $('.J_cate_list').removeClass('hide');
                        $('.J_menu').removeClass('hide');
                        $('.J_shopInfo').addClass('hide');
                    }

                    if (text == '详情') {
                        $('.J_cate_list').addClass('hide');
                        $('.J_menu').addClass('hide');
                        $('.J_shopInfo').removeClass('hide');
                    }
                })


                $('.J_plus').on('touchstart', function () {

                    var num = Number($(this).siblings('.J_num').find('span').text());
                    num += 1;
                    $(this).siblings('.J_num').find('span').text(num);
                    $(this).siblings('.J_input_num').val(num);
                    $.fn_calculate_account();
                })

                $('.J_minus').on('touchstart', function () {
                    var num = Number($(this).siblings('.J_num').find('span').text());
                    if (num != 0) {
                        num -= 1;
                        $(this).siblings('.J_num').find('span').text(num);
                        $(this).siblings('.J_input_num').val(num);
                    }
                    $.fn_calculate_account();
                })


                $('.J_submit').on('touchstart', function () {


                    var gids = new Array();
                    var gnums = new Array();
                    var order_account = $('.J_input_account').val();

                    $('.J_spec_container').find('.J_input_id').each(function () {
                        gids.push($(this).val());
                    })

                    $('.J_spec_container').find('.J_input_num').each(function () {
                        gnums.push($(this).val());
                    })


                    $.ajax({
                        url: '<?php echo site_url('hm/order/order_edit')?>',
                        cache: false,
                        dataType: 'json',
                        type: 'POST',
                        data: {
                            order_account: order_account,
                            order_id: orderId,
                            gids: gids.join(','),
                            gnums: gnums.join(',')
                        },
                        beforeSend: function () {

                        },
                        success: function (data) {


                            if (data.status == 1) {
                                layer.msg(data.info, {
                                    time: 2000  //2秒关闭（如果不配置，默认是3秒）
                                }, function () {
//                                window.location.reload();
                                });

                            } else {
                                layer.msg(data.info);
                            }
                        }
                    });
                })
            })

            $('.J_status_operate').click(function () {

                var text = $(this).text();
                var status = $(this).data('value');



                if(roomSelect == 0 && status == 5)
                {
                    layer.msg('未安排房间的订单 , 不可以操作入住 !');
                    return false;
                }

                layer.confirm('确定需要' + text + '?', {
                    btn: ['确定', '取消'] //按钮
                }, function () {

                    $.post('<?php echo $edit_status_url;?>', {
                        order_id: orderId,
                        status: status
                    }, function (data) {
                        layer.msg(data.info);
                        if (data.status == '1') {
                            layer.msg(data.info, {
                                time: 2000
                            }, function () {
                                window.location.reload();
                            });
                        }
                    }, 'json')
                }, function () {
                    layer.close();
                });
            })
        })
    </script>
    <div class="cart J_cart">

        <div class="cart-cont">

            <div class="btn-box">
                <div class="J_exp brief">
                    <div class="brief-btn"><p class="price">
                            <span>¥</span><span class="J_order_account"><?php echo $order_info['order_account']; ?></span>
                        </p>
                        <p class="min-del" style="visibility: hidden">
                            外送费￥2.5</p></div>
                </div>
                <?php if (!in_array($order_info['order_status'], array(3, 6))): ?>
                    <div class="btn J_submit">
                        <div>修改订单</div>
                    </div>

                <?php endif; ?>

                <?php if ($order_info['order_status'] == 1): ?>
                    <div class="status-btn">
                        <div class="btn_success J_status_operate" data-value="2">
                            审核通过
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ($order_info['order_status'] != 3  ): ?>
                    <div class="status-btn">
                        <div class="btn_red J_status_operate" data-value="3">
                            取消订单
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ($order_info['order_status'] == 2): ?>
                    <div class="status-btn">
                        <div class="btn_other J_status_operate" data-value="4">
                            确认订单
                        </div>
                    </div>
                <?php endif; ?>

                <?php if ($order_info['order_status'] == 4 && $hotel_order_info['start_date'] <= date('Y-m-d')) : ?>
                    <div class="status-btn">
                        <div class="btn_other J_status_operate" data-value="5">
                            操作已入住
                        </div>
                    </div>
                <?php endif; ?>
                <?php if ($order_info['order_status'] == 5 && $hotel_order_info['end_date'] <= date('Y-m-d')): ?>

                    <div class="status-btn">
                        <div class="btn_error J_status_operate" data-value="6">
                            完成订单
                        </div>
                    </div>
                <?php endif; ?>

                <!--<div class="status-btn">
                    <div class="btn_other" onclick="history.go(-1)">返回</div>
                </div>-->

            </div>
        </div>
    </div>


</div>

</body>
</html>